package com.lee.treasure.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lee
 * @since 2019-11-22
 */
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .allowCredentials(true).maxAge(3600);
    }

//    @Bean
//    public HttpMessageConverter<String> responseBodyStringConverter() {
//        return new StringHttpMessageConverter(StandardCharsets.UTF_8);
//    }

//    修改StringHttpMessageConverter默认配置
//    @Override
//    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//        converters.add(responseBodyStringConverter());
//        converters.add(new MappingJackson2HttpMessageConverter());
//    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/uploads/**").addResourceLocations("file:///D:\\");
//    }
}
